<template>
	<view class="container">
		<view class="header">
			<view class="status_bar" :style="'height:'+height+'px;'"></view>
			<view class="nav-bar">
				<view class="nav-left" @click="back">
					<u-icon name="arrow-left" size="40" color="#333"></u-icon>
				</view>
				<view class="nav-title">用户详情</view>
				<view class="nav-right"></view>
			</view>
		</view>

		<view class="user-card">
			<view class="user-avatar">
				<image :src="userInfo.avatar || '/static/siji.png'" mode="aspectFill"></image>
			</view>
			<view class="user-info">
				<view class="user-name">{{userInfo.nickname || userInfo.truename || '未设置'}}</view>
				<view class="user-phone">{{formatPhone(userInfo.mobile)}}</view>
				<view class="user-level">
					<text class="level-text">LV{{userInfo.level || 1}}</text>
					<text class="growth-text">成长值: {{userInfo.growthValue || 0}}</text>
				</view>
			</view>
		</view>

		<!-- 统计卡片 -->
		<view class="stats-section">
			<view class="section-title">出行统计</view>
			<view class="stats-grid">
				<view class="stat-card">
					<view class="stat-value">{{userInfo.totalOrders || 0}}</view>
					<view class="stat-label">总订单数</view>
				</view>
				<view class="stat-card">
					<view class="stat-value">{{userInfo.completedOrders || 0}}</view>
					<view class="stat-label">已完成</view>
				</view>
				<view class="stat-card">
					<view class="stat-value">{{formatDistance(userInfo.kilometersAll)}}</view>
					<view class="stat-label">总里程(km)</view>
				</view>
				<view class="stat-card">
					<view class="stat-value">{{formatMoney(userInfo.payMoneyAll)}}</view>
					<view class="stat-label">总消费(元)</view>
				</view>
			</view>
		</view>

		<!-- 本月统计 -->
		<view class="stats-section">
			<view class="section-title">本月统计</view>
			<view class="stats-grid">
				<view class="stat-card">
					<view class="stat-value">{{userInfo.monthOrders || 0}}</view>
					<view class="stat-label">本月订单</view>
				</view>
				<view class="stat-card">
					<view class="stat-value">{{formatDistance(userInfo.kilometersMonth)}}</view>
					<view class="stat-label">本月里程(km)</view>
				</view>
				<view class="stat-card">
					<view class="stat-value">{{formatMoney(userInfo.payMoneyMonty)}}</view>
					<view class="stat-label">本月消费(元)</view>
				</view>
				<view class="stat-card">
					<view class="stat-value">{{userInfo.avgRating || 0}}</view>
					<view class="stat-label">平均评分</view>
				</view>
			</view>
		</view>

		<!-- 账户信息 -->
		<view class="account-section">
			<view class="section-title">账户信息</view>
			<view class="account-list">
				<u-cell-item title="账户余额" :value="formatMoney(userInfo.balance) + '元'" :arrow="false">
					<view slot="icon" class="cell-icon">
						<u-icon name="wallet" size="44" color="#43D0C3"></u-icon>
					</view>
				</u-cell-item>
				<u-cell-item title="优惠券" :value="(userInfo.coupon_count || 0) + '张'" :arrow="false">
					<view slot="icon" class="cell-icon">
						<u-icon name="gift" size="44" color="#F56C6C"></u-icon>
					</view>
				</u-cell-item>
				<u-cell-item title="积分" :value="userInfo.points || 0" :arrow="false">
					<view slot="icon" class="cell-icon">
						<u-icon name="integral" size="44" color="#E6A23C"></u-icon>
					</view>
				</u-cell-item>
			</view>
		</view>

		<!-- 认证信息 -->
		<view class="verify-section">
			<view class="section-title">认证信息</view>
			<view class="verify-list">
				<u-cell-item title="实名认证" :value="getRealNameStatus()" :arrow="false">
					<view slot="icon" class="cell-icon">
						<u-icon name="auth" size="44" :color="userInfo.realNameStatus === 1 ? '#67C23A' : '#909399'"></u-icon>
					</view>
				</u-cell-item>
				<u-cell-item v-if="userInfo.realNameTime" title="认证时间" :value="formatTime(userInfo.realNameTime)" :arrow="false">
					<view slot="icon" class="cell-icon">
						<u-icon name="clock" size="44" color="#909399"></u-icon>
					</view>
				</u-cell-item>
			</view>
		</view>
	</view>
</template>

<script>
	import { mapState } from 'vuex';
	
	export default {
		data() {
			return {
				
			}
		},
		computed: {
			...mapState(['userInfo', 'height'])
		},
		onLoad() {
			// 刷新用户信息
			this.$store.dispatch('updateUserInfo');
		},
		methods: {
			back() {
				uni.navigateBack();
			},
			// 格式化手机号
			formatPhone(phone) {
				if (!phone) return '未绑定';
				return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
			},
			// 格式化金额
			formatMoney(amount) {
				if (!amount) return '0.00';
				return parseFloat(amount).toFixed(2);
			},
			// 格式化距离
			formatDistance(distance) {
				if (!distance) return '0';
				return parseFloat(distance).toFixed(1);
			},
			// 格式化时间
			formatTime(time) {
				if (!time) return '';
				const date = new Date(time);
				return date.getFullYear() + '-' + 
					   String(date.getMonth() + 1).padStart(2, '0') + '-' + 
					   String(date.getDate()).padStart(2, '0');
			},
			// 获取实名认证状态
			getRealNameStatus() {
				const status = this.userInfo.realNameStatus || this.userInfo.real_verified;
				switch(status) {
					case 1: return '已认证';
					case 2: return '审核中';
					case -1: return '审核失败';
					default: return '未认证';
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		background-color: #f5f5f5;
		min-height: 100vh;
	}

	.header {
		background: white;
		box-shadow: 0 2px 8px rgba(0,0,0,0.1);
		
		.nav-bar {
			display: flex;
			align-items: center;
			height: 88rpx;
			padding: 0 30rpx;
			
			.nav-left {
				width: 80rpx;
			}
			
			.nav-title {
				flex: 1;
				text-align: center;
				font-size: 36rpx;
				font-weight: 500;
				color: #333;
			}
			
			.nav-right {
				width: 80rpx;
			}
		}
	}

	.user-card {
		background: white;
		margin: 20rpx 30rpx;
		padding: 40rpx;
		border-radius: 20rpx;
		display: flex;
		align-items: center;
		box-shadow: 0 4px 12px rgba(0,0,0,0.1);
		
		.user-avatar {
			width: 120rpx;
			height: 120rpx;
			border-radius: 60rpx;
			overflow: hidden;
			margin-right: 30rpx;
			
			image {
				width: 100%;
				height: 100%;
			}
		}
		
		.user-info {
			flex: 1;
			
			.user-name {
				font-size: 36rpx;
				font-weight: 500;
				color: #333;
				margin-bottom: 12rpx;
			}
			
			.user-phone {
				font-size: 28rpx;
				color: #666;
				margin-bottom: 12rpx;
			}
			
			.user-level {
				display: flex;
				align-items: center;
				
				.level-text {
					background: linear-gradient(90deg, #43D0C3, #36C3A6);
					color: white;
					padding: 6rpx 16rpx;
					border-radius: 20rpx;
					font-size: 24rpx;
					margin-right: 20rpx;
				}
				
				.growth-text {
					font-size: 24rpx;
					color: #999;
				}
			}
		}
	}

	.stats-section, .account-section, .verify-section {
		margin: 20rpx 30rpx;
		
		.section-title {
			font-size: 32rpx;
			font-weight: 500;
			color: #333;
			margin-bottom: 20rpx;
		}
	}

	.stats-grid {
		display: grid;
		grid-template-columns: repeat(2, 1fr);
		gap: 20rpx;
		
		.stat-card {
			background: white;
			padding: 30rpx;
			border-radius: 16rpx;
			text-align: center;
			box-shadow: 0 2px 8px rgba(0,0,0,0.06);
			
			.stat-value {
				font-size: 40rpx;
				font-weight: bold;
				color: #43D0C3;
				margin-bottom: 12rpx;
			}
			
			.stat-label {
				font-size: 26rpx;
				color: #666;
			}
		}
	}

	.account-list, .verify-list {
		background: white;
		border-radius: 16rpx;
		overflow: hidden;
		box-shadow: 0 2px 8px rgba(0,0,0,0.06);
		
		.cell-icon {
			display: flex;
			align-items: center;
			margin-right: 20rpx;
		}
	}
</style>






